var locationData = require("../../staticData/locationData");
exports.search_organization_location_user = function(req,res) {

    //获取restful参数
    var restfulParams = req.routeInfo.restfulParams;

    //最终结果
    var resultData = {};

    //任务流创建
    async.waterfall([

        //获取助力活动参赛者列表
        function(cb){

            R.SEND_HTTP(
                req,
                {
                    url    : CORE_APIConfig.coreAPI.searchOrganizationLocationUser + "/o_id/" + restfulParams.o_id  ,
                    method : 'POST',
                    data   : {
                        fields : [
                            "o_uid",
                            "o_logo",
                            "o_name",
                            "o_tags",
                            "o_address",
                            "o_longitude",
                            "o_latitude",
                            "o_slogan",
                            "o_desc",
                            "o_mail",
                            "o_phone",
                            "o_contact",
                            "o_provinces",
                            "o_city",
                            "o_area",
                            "u_realname",
                            "u_phone",
                            "o_contact",
                            "o_phone"
                        ].join(",")
                    }
                },
                function (err, data) {
                    
                    if(data.data.length>0){
                        data.data[0].o_provinces_id = data.data[0].o_provinces;
                        data.data[0].o_city_id = data.data[0].o_city;
                        data.data[0].o_area_id = data.data[0].o_area;
                        data.data[0].o_provinces = locationData[data.data[0].o_provinces];
                        data.data[0].o_city = locationData[data.data[0].o_city];
                        data.data[0].o_area = locationData[data.data[0].o_area];


                        resultData.organizationData = data.data[0];
                        cb()
                    }else{
                        console.log(132);
                        R.SEND_HTTP(
                            req,
                            {
                                url    : CORE_APIConfig.coreAPI.searchOrganization + "/o_id/" + restfulParams.o_id,
                                method : 'POST',
                                data   : {
                                    fields : [
                                        "o_logo",
                                        "o_name",
                                        "o_tags",
                                        "o_address",
                                        "o_longitude",
                                        "o_latitude",
                                        "o_slogan",
                                        "o_desc",
                                        "o_mail",
                                        "o_provinces",
                                        "o_city",
                                        "o_area",
                                        "o_contact",
                                        "o_phone"
                                    ].join(",")
                                }
                            },
                            function (err, data) {


                                    if(data.data.length > 0){

                                        data.data[0].o_provinces_id = data.data[0].o_provinces;
                                        data.data[0].o_city_id = data.data[0].o_city;
                                        data.data[0].o_area_id = data.data[0].o_area;
                                        data.data[0].o_provinces = locationData[data.data[0].o_provinces];
                                        data.data[0].o_city = locationData[data.data[0].o_city];
                                        data.data[0].o_area = locationData[data.data[0].o_area];
                                        resultData.organizationData = data.data[0];

                                    }
                                    
                                    cb();
                            }
                        );
                    }

                }
            );
        },


    ],function(err, result){

        //返回最终拼接结果
        RES.response(res,true,resultData);

    });

}


























